﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GeostatisticalTool.Classes;

namespace GeostatisticalTool.Forms
{
    public class LagControl : UserControl
    {
        private SpatialContinuity spatial;

        private Label label1;
        private Label label2;
        private Label label3;
        private TextBox uxNumberOfLags;
        private TextBox uxLagSize;
        private TextBox uxTolerance;
        private Panel panel1;
        private Button uxUpdateLag;

        public SpatialContinuity Spatial
        {
            get { return spatial; }
            set { spatial = value; }
        }

        public String NumberOfLags
        {
            get { return this.uxNumberOfLags.Text; }
            set { this.uxNumberOfLags.Text = value; }
        }

        public String LagSize
        {
            get { return this.uxLagSize.Text; }
            set { this.uxLagSize.Text = value; }
        }

        public String Tolerance
        {
            get { return this.uxTolerance.Text; }
            set { this.uxTolerance.Text = value; }
        }


        public void EnableUpdateLag()
        {
         this.uxUpdateLag.Enabled=false;
        }

        public LagControl()
        {
            InitializeComponent();
        }


        private void uxUpdateLag_Click(object sender, EventArgs e)
        {
            if (spatial == null)
                return;

            if (Validator.IsInt32(uxNumberOfLags) && Convert.ToInt16(uxNumberOfLags.Text) > 5 &&
                (Validator.IsDouble(uxLagSize) && Convert.ToDouble(uxLagSize.Text) > 0) &&
                Validator.IsGreaterThanValue(uxTolerance, 0) && Validator.IsLowerThanValue(uxTolerance, 1))
            {
                spatial.LagValue = new Lag(Convert.ToInt16(uxNumberOfLags.Text), Convert.ToDouble(uxLagSize.Text), Convert.ToDouble(uxTolerance.Text));
                this.uxUpdateLag.Enabled = false;
            }

           

        }

        private void uxNumLags_TextChanged(object sender, EventArgs e)  
        {

            this.uxUpdateLag.Enabled = true;
        }

        private void uxLagSize_TextChanged(object sender, EventArgs e)
        {

            this.uxUpdateLag.Enabled = true;
        }

        private void uxTolerance_TextChanged(object sender, EventArgs e)
        {

            this.uxUpdateLag.Enabled = true;
        }

        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.uxNumberOfLags = new System.Windows.Forms.TextBox();
            this.uxLagSize = new System.Windows.Forms.TextBox();
            this.uxTolerance = new System.Windows.Forms.TextBox();
            this.uxUpdateLag = new System.Windows.Forms.Button();
            this.panel1 = new System.Windows.Forms.Panel();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(24, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(85, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Number of Lags:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(24, 39);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(49, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "Lag size:";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(24, 65);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(58, 13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Tolerance:";
            // 
            // uxNumberOfLags
            // 
            this.uxNumberOfLags.Location = new System.Drawing.Point(115, 12);
            this.uxNumberOfLags.Name = "uxNumberOfLags";
            this.uxNumberOfLags.Size = new System.Drawing.Size(100, 20);
            this.uxNumberOfLags.TabIndex = 3;
            this.uxNumberOfLags.TextChanged += new System.EventHandler(this.uxNumLags_TextChanged);
            // 
            // uxLagSize
            // 
            this.uxLagSize.Location = new System.Drawing.Point(115, 39);
            this.uxLagSize.Name = "uxLagSize";
            this.uxLagSize.Size = new System.Drawing.Size(100, 20);
            this.uxLagSize.TabIndex = 4;
            this.uxLagSize.TextChanged += new System.EventHandler(this.uxLagSize_TextChanged);
            // 
            // uxTolerance
            // 
            this.uxTolerance.Location = new System.Drawing.Point(115, 65);
            this.uxTolerance.Name = "uxTolerance";
            this.uxTolerance.Size = new System.Drawing.Size(100, 20);
            this.uxTolerance.TabIndex = 5;
            this.uxTolerance.TextChanged += new System.EventHandler(this.uxTolerance_TextChanged);
            // 
            // uxUpdateLag
            // 
            this.uxUpdateLag.Enabled = false;
            this.uxUpdateLag.Location = new System.Drawing.Point(27, 88);
            this.uxUpdateLag.Name = "uxUpdateLag";
            this.uxUpdateLag.Size = new System.Drawing.Size(75, 23);
            this.uxUpdateLag.TabIndex = 6;
            this.uxUpdateLag.Text = "Update Lag";
            this.uxUpdateLag.UseVisualStyleBackColor = true;
            this.uxUpdateLag.Click += new System.EventHandler(this.uxUpdateLag_Click);
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.label2);
            this.panel1.Controls.Add(this.uxUpdateLag);
            this.panel1.Controls.Add(this.label1);
            this.panel1.Controls.Add(this.uxTolerance);
            this.panel1.Controls.Add(this.label3);
            this.panel1.Controls.Add(this.uxLagSize);
            this.panel1.Controls.Add(this.uxNumberOfLags);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(231, 116);
            this.panel1.TabIndex = 7;
            this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
            // 
            // LagControl
            // 
            this.Controls.Add(this.panel1);
            this.Name = "LagControl";
            this.Size = new System.Drawing.Size(231, 116);
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.ResumeLayout(false);

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
